package de.hijacksoft.isle.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import de.hijacksoft.isle.classes.Price;
import de.hijacksoft.isle.R;
import de.hijacksoft.isle.classes.Recipe;

/**
 * The Adapter for the ListView used in the RecipeSelectActivity
 * @author HiJackSoft
 */
public class RecipeListAdapter extends BaseAdapter {

    // Constants
    private static final String TAG = "RecipeListAdapter";
    private int id;
    private ArrayList<Recipe> items;
    private Context context;

    public RecipeListAdapter(Context context, int textViewResourceId, ArrayList<Recipe> objects) {
        id = textViewResourceId;
        items = objects;
        this.context = context;
    }

    public void onDataSetChange() {
        // this method wants to be implemented <3
    }

    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
        onDataSetChange();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        if (convertView == null) {
            LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflator.inflate(id, null);
        }

        ImageView photo = (ImageView) convertView.findViewById(R.id.recipe_photo);
        RatingBar rating = (RatingBar) convertView.findViewById(R.id.recipe_rating);
        TextView name = (TextView) convertView.findViewById(R.id.recipe_name);
        TextView info = (TextView) convertView.findViewById(R.id.recipe_info);

        photo.setVisibility(View.GONE);//no photos for recipes
        rating.setRating((float) items.get(position).rating);
        name.setText(items.get(position).name);
        info.setText(new Price(context, items.get(position).getPrice()).toString());

        return convertView;

    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int arg0) {
        return items.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }
}
